package ca.concordia.soen6461.wichf.navigation.view;

import static ca.concordia.soen6461.wichf.navigation.view.HomeView.getDate;

import java.util.Date;

import ca.concordia.soen6461.wichf.controller.Event;
import ca.concordia.soen6461.wichf.entity.ScheduledEvent;
import ca.concordia.soen6461.wichf.entity.User;
import ca.concordia.soen6461.wichf.navigation.event.AvailabilityFromEvent;
import ca.concordia.soen6461.wichf.navigation.event.AvailabilityToEvent;
import ca.concordia.soen6461.wichf.navigation.event.UnavailabilityToEvent;
import ca.concordia.soen6461.wichf.navigation.view.HomeViewBean.TimeSlot;
import ca.concordia.soen6461.wichf.service.SchedulingService;

public class DoctorHomeView extends BaseHomeView {
	
	public static class AvailabilityLimit {
		
		private int day;
		private int slot;
		
		public AvailabilityLimit(int day, int slot) {
			this.day = day;
			this.slot = slot;
		}

		public int getDay() {
			return day;
		}

		public int getSlot() {
			return slot;
		}
		
	}

	private SchedulingService schedulingService;
	
	public DoctorHomeView(SchedulingService schedulingService) {
		this.schedulingService = schedulingService;
	}

	@Override
	protected void populateSlot(Event event, User user, int d, int t, TimeSlot slot) {
		Date time = getDate(d, t).getTime();
		SchedulingService.ClinicStatus clinicStatus = schedulingService.clinicStatus(user, time);
		ScheduledEvent userAppointment = clinicStatus.getAppointment();
		slot.setAppointment(userAppointment != null);
		AvailabilityLimit limit = event.getSession().get(AvailabilityLimit.class);
		if (limit == null) {
			slot.getActions().put(AvailabilityFromEvent.class.getSimpleName(), "...");
		} else if (limit.getDay() == d && limit.getSlot() <= t) {
			if (slot.isAppointment()) {
				slot.getActions().put(UnavailabilityToEvent.class.getSimpleName(), "xxx");
			} else {
				slot.getActions().put(AvailabilityToEvent.class.getSimpleName(), "+++");
			}
		}
	}

}
